<?php
ob_start();

class Pager
{
	
	public $year=0;
	public $month=0;
	public $bc_srch="";
	public $param="";
	public $limit=1;
	public $start=1;
	public $page=1;
	public $key_srch="";
	public $kind_key="";
	public $zone_key='';
	public $status_key='';
	public $order_key='';
	public $link="";
    public $loadLink="";
    public $id=0;
    public $ageFrom=0;
    public $ageTo=0;
    public $sex=0;
    public $address='';

    public $active='';

    public function setActive($active){
        $this->active=$active;
    }
	
	public function setKeySrch($s){
		$this->key_srch=$s;
	}
	public function setKindKey($k){
		$this->kind_key=$k;
	}
	public function setZoneKey($k){
		$this->zone_key=$k;
	}
	public function setStatusKey($k){
		$this->status_key=$k;
	}
	public function setOrderKey($k){
		$this->order_key=$k;
	}
    public function setAgeFrm($k){
        $this->ageFrom=$k;
    }
    public function setAgeTo($k){
        $this->ageTo=$k;
    }
    public function setStart($s){
        $this->start=$s;
    }
    public function setSex($s){
        $this->sex=$s;
    }
    public function setId($id){
        $this->id=$id;
    }
    public function setAddress($add){
        $this->address=$add;
    }

    public function getAddress(){
        return $this->address;
    }
    public function getSex(){
        return $this->sex;
    }
    public function getStart(){
        return $this->start;
    }
    public function setLimit($l){
        $this->limit=$l;
    }
	public function getKeySrch(){
		return $this->key_srch;
	}
	public function getKindKey(){
		return $this->kind_key;
	}
	public function getZoneKey(){
		return $this->zone_key;
	}
	public function getStatusKey(){
		return $this->status_key;
	}
	public function getOrderKey(){
		return $this->order_key;
	}

	public function getLimit(){
		return $this->limit;
	}
	public function setPage($p){
		$this->page=$p;
	}
	public function getPage(){
		return $this->page;
	}
    public function  getId(){
    return $this->id;
    }
    public function  getAgeFrm(){
        return $this->ageFrm;
    }
    public function  getAgeTo()
    {
        return $this->ageTo;
    }

    function  getActive(){
        return $this->active;
    }


    public function findStart($limit)
    {
		if((!isset($_GET['page'])) || ($_GET['page']=="1"))
		{
			$start = 0;
			$_GET['page'] =1;
		}   
		else
		{
			$start =($_GET['page']-1 )* $limit;
		}
		$this->start=$start;
		return $start;
	}
   	
	function findPages($count, $limit)
	{
		   $pages = (($count % $limit) ==0)? $count/$limit: floor($count/$limit) +1;
		   $this->setPage($pages);
		   return $pages;
	}
	
	public function setLink(){
		$this->link='&id='.$this->getId().'&keyword='.$this->getKeySrch().'&permit='.$this->getKindKey()
            .'&sex='.$this->getSex().'&ageFrom='.$this->getAgeFrm().'&ageTo='.$this->getAgeTo().
            '&address='.$this->getAddress().'&online='.$this->getStatusKey().
            '&active='.$this->getActive();
	}
	public function getLink(){
		return $this->link;
	}
	public function pageList($curpage, $pages,$loadLink='')
	{
        if($loadLink == ''){
            $loadLink=$_SERVER['PHP_SELF'];
        }
		$page_list ="";
		/* In trang dau tien va nhung link toi trang truoc neu can */
		if (($curpage >1) && ($curpage))
		{
		   $page_list .='<a class="pag_nav"  href="'.$loadLink.'?page=1'.$this->getLink().'"> Begin|   </a>';
	
		}
		
		if(($curpage-1) >0 )
		{
		   $page_list .='<a class="pag_nav" title="prev" href="'.$loadLink.'?page='.($curpage-1).$this->getLink().'"> << </a>';
	
		}	
		
		/* In ra danh sach cac trang va lam cho trang hien tai dam hon va mat link o chan */    
		for($i=1; $i<=$pages; $i++)
		{
		   if($i == $curpage)
		   {
			  $page_list .='<b id="pag_nav" style="color:red; text-decoration:underline" title="page '.$i.'" class="pag_nav">'.$i.'</b>';
		   }
		   else
		   {
			  $page_list .='<a class="pag_nav" title="goto '.$i.'" href ="'.$loadLink.'?page='.$i.$this->getLink().'" >'.  $i  .'</a>';
		   }
		   $page_list .="  ";
		}
		
		
		/* In link cua trang tiep theo va trang cuoi cung neu can */
		if(($curpage+1) <= $pages)
		{
		   $page_list .='<a class="pag_nav" title="next" href="'.$loadLink.'?page='.($curpage+1).$this->getLink().'"> >> </a>';
	
		}

		if(($curpage !=$pages) && ($pages !=0))
		{
		$page_list .='<a class="pag_nav"  href ="'.$loadLink.'?page='.$pages.$this->getLink().'"> |End</a>';
		}
		
		//$page_list .="</td>\n";
	
		return $page_list;	
	
		}
}
?>